import React from "react";
import avatar from '../images/avatar.png'
export class Form extends React.Component {
  state = {
    txt: '',
  };

  txtRef = React.createRef();
  handleAdd = () => {
    if (this.state.txt !== '') {
      this.props.addComment(this.state.txt);
      this.setState({
        txt: '',
      });
    }

    this.txtRef.current.focus();
  };

  handleTxt = (e) => {
    this.setState({
      txt: e.target.value,
    });
  };

  render() {
    return (
      <div className="comment-send-container">
        <div>
          <img className="user-head" src={avatar} alt="头像" />
        </div>
        <div className="comment-send">
          <div className="textarea-container">
            <textarea
              cols="80"
              rows="5"
              placeholder="发条友善的评论"
              className="ipt-txt"
              value={this.state.txt}
              onChange={this.handleTxt}
              ref={this.txtRef}
            />
            <button className="comment-submit" onClick={this.handleAdd}>发表评论</button>
          </div>
          <div className="comment-emoji">
            <i className="face"></i>
            <span className="text">表情</span>
          </div>
        </div>
      </div>
    )
  }
}